import { FC, useState } from "react";
const StateDemo01: FC = () => {
  //useState可以触发组件更新
  const [count, setCount] = useState(0);
  // const [name, setName] = useState("张三");

  // 点击累加
  function add() {
    // setCount(count + 1);
    setCount((count) => count + 1);
    setCount((count) => count + 1);
    setCount((count) => count + 1);
    setCount((count) => count + 1);
    setCount((count) => count + 1);

    console.log(count);

    //如果一个变量不用于jsx中显示，不要用useState管理它，用useRef.
    // setName("李四");
  }

  return (
    <>
      <button onClick={add}> click to accumulate：{count} </button>
    </>
  );
};

export default StateDemo01;
